package com.chrray.position.service.web.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chrray.position.domain.FdCustomerService;
import com.chrray.position.domain.dto.FdCustomerServiceDTO;
import com.chrray.position.domain.dto.search.FdCustomerServiceSearch;
import com.chrray.position.domain.vo.FdCustomerServiceVO;
import com.chrray.position.exception.ServiceException;
import com.chrray.position.mapper.position.FdCustomerServiceMapper;
import com.chrray.position.service.position.FdCustomerServiceService;
import com.chrray.position.service.web.WFdCustomerServiceService;
import com.chrray.position.util.result.ResponseResult;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

import static com.chrray.position.util.result.ResponseResults.success;

/**
 * 客服配置表 接口实现类
 *
 * @author wusiwee
 * @email wusiwee@163.com
 * @since 1.0.1 2024-08-07
 */
@Service
@AllArgsConstructor
public class WFdCustomerServiceServiceImpl extends ServiceImpl<FdCustomerServiceMapper, FdCustomerService> implements WFdCustomerServiceService {


    @Override
    public FdCustomerService selectOne() {
        LambdaQueryWrapper<FdCustomerService> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.last(" limit 1");
        return baseMapper.selectOne(lambdaQueryWrapper);
    }

    @Override
    public ResponseResult saveCustomer(FdCustomerService entity) {
        FdCustomerService fdCustomerService = this.selectOne();
        if (ObjectUtils.isNotEmpty(fdCustomerService)) {
            fdCustomerService.setDescription(entity.getDescription());
            fdCustomerService.setImage(entity.getImage());
            fdCustomerService.setPhone(entity.getPhone());
            baseMapper.updateById(fdCustomerService);
        } else {
            baseMapper.insert(entity);
        }
        return  success();
    }
}
